package com.killuasy.tools.servlet.payrollComputation;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.killuasy.tools.model.Salary;

public class Count extends HttpServlet {

	private static final long serialVersionUID = -1268508543970136531L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		Salary salary = new Salary();

		try {
			BeanUtils.copyProperties(salary, request.getParameterMap());
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		try {
			// 收入 : 工资 / 月工作时数 * （ 实际工作时数 + 双休日工作时数 ）
			salary.set收入(salary.get工资() * (salary.get实际工作时数() + salary.get双休日工作时数())/ salary.get月工作时数());
		} catch (Exception e) {
			salary.set收入(0);
		}

		try {
			// 补贴 : 饭补 + 车补 + 奖金
			salary.set补贴(salary.get饭补() + salary.get车补() + salary.get奖金());
		} catch (Exception e) {
			salary.set补贴(0);
		}
		try {
			// 养老 - 健康 - 其他各种险
			salary.set扣除(salary.get养老() + salary.get健康() + salary.get其他各种险());
		} catch (Exception e) {
			salary.set扣除(0);
		}
		
		salary.set净利润(salary.get收入() + salary.get补贴() - salary.get扣除());

		request.setAttribute("Salary", salary);
		request.getRequestDispatcher("/payrollComputation.jsp").forward(
				request, response);

	}
}
